/*
 * Copyright (C) 2017 Gautam Chibde
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.chibde.audiovisualizer.sample;

import com.chibde.audiovisualizer.sample.visualizer.BarVisualizerAbility;
import com.chibde.audiovisualizer.sample.visualizer.CircleBarVisualizerAbility;
import com.chibde.audiovisualizer.sample.visualizer.CircleVisualizerAbility;
import com.chibde.audiovisualizer.sample.visualizer.LineBarVisualizerAbility;
import com.chibde.audiovisualizer.sample.visualizer.LineVisualizerAbility;
import com.chibde.audiovisualizer.sample.visualizer.SquareBarVisualizerAbility;
import com.chibde.visualizer.ResourceTable;

import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.Text;
import ohos.agp.utils.Color;
import ohos.agp.window.service.WindowManager;

public class MainAbility extends Ability {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        WindowManager.getInstance().getTopWindow().get().setStatusBarColor(Color.getIntColor("#303F9F"));
        Text title_name = (Text) findComponentById(ResourceTable.Id_tv_title_name);
        Component back = findComponentById(ResourceTable.Id_im_back);
        title_name.setText("AudioVisualizer");
        back.setVisibility(Component.HIDE);

        // 获取资源ID
        Button line = (Button) findComponentById(ResourceTable.Id_line);
        line.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                line(component);
            }
        });
        Button bar = (Button) findComponentById(ResourceTable.Id_bar);
        bar.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                bar(component);
            }
        });
        Button circle = (Button) findComponentById(ResourceTable.Id_circle);
        circle.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                circle(component);
            }
        });
        Button circleBar = (Button) findComponentById(ResourceTable.Id_circleBar);
        circleBar.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                circleBar(component);
            }
        });
        Button lineBar = (Button) findComponentById(ResourceTable.Id_lineBar);
        lineBar.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                lineBar(component);
            }
        });
        Button service = (Button) findComponentById(ResourceTable.Id_service);
        service.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                service(component);
            }
        });
        Button square = (Button) findComponentById(ResourceTable.Id_square);
        square.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                square(component);
            }
        });
    }

    /**
     * line
     *
     * @param component
     */
    public void line(Component component) {
        Intent intent = new Intent();
        Operation build = new Intent.OperationBuilder()
                .withBundleName(getBundleName())
                .withAbilityName(LineVisualizerAbility.class.getName())
                .build();
        intent.setOperation(build);
        startAbility(intent);
    }

    /**
     * bar
     *
     * @param component
     */
    public void bar(Component component) {
        Intent intent = new Intent();
        Operation build = new Intent.OperationBuilder()
                .withBundleName(getBundleName())
                .withAbilityName(BarVisualizerAbility.class.getName())
                .build();
        intent.setOperation(build);
        startAbility(intent);
    }

    /**
     * circle
     *
     * @param component
     */
    public void circle(Component component) {
        Intent intent = new Intent();
        Operation build = new Intent.OperationBuilder()
                .withBundleName(getBundleName())
                .withAbilityName(CircleVisualizerAbility.class.getName())
                .build();
        intent.setOperation(build);
        startAbility(intent);
    }

    /**
     * circleBar
     *
     * @param component
     */
    public void circleBar(Component component) {
        Intent intent = new Intent();
        Operation build = new Intent.OperationBuilder()
                .withBundleName(getBundleName())
                .withAbilityName(CircleBarVisualizerAbility.class.getName())
                .build();
        intent.setOperation(build);
        startAbility(intent);
    }

    /**
     * lineBar
     *
     * @param component
     */
    public void lineBar(Component component) {
        Intent intent = new Intent();
        Operation build = new Intent.OperationBuilder()
                .withBundleName(getBundleName())
                .withAbilityName(LineBarVisualizerAbility.class.getName())
                .build();
        intent.setOperation(build);
        startAbility(intent);
    }

    /**
     * service
     *
     * @param component
     */
    public void service(Component component) {
        Intent intent = new Intent();
        Operation build = new Intent.OperationBuilder()
                .withBundleName(getBundleName())
                .withAbilityName(ServiceExampleAbility.class.getName())
                .build();
        intent.setOperation(build);
        startAbility(intent);
    }

    /**
     * square
     *
     * @param component
     */
    public void square(Component component) {
        Intent intent = new Intent();
        Operation build = new Intent.OperationBuilder()
                .withBundleName(getBundleName())
                .withAbilityName(SquareBarVisualizerAbility.class.getName())
                .build();
        intent.setOperation(build);
        startAbility(intent);
    }
}
